﻿<?php
include("remove2.php");
$cc=$_GET['cc'];
$ve=$_GET['ve'];
$name=$_POST['name'];
$url=$_POST['url'];
if($name=="")$name="qt3gcom";
if($url=="")$url="http://wap.qt3g.com";
if($name=="" && $url=="")
{
$name="晴天3G建站系统";
$url="http://wap.qt3g.com";
}

function randname()
	{
		$s="";
		$abc="abcdefghijklmnopqrstuvwxyzVABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		$abclen=strlen($abc);
		for($i=0;$i<10;$i++)
		{
			$s.=substr($abc,rand(1,$abclen-1),1);
		}
		return $s;
	}

function xCopy($source, $destination, $child){
    //用法：
    // xCopy("feiy","feiy2",1):拷贝feiy下的文件到 feiy2,包括子目录
    // xCopy("feiy","feiy2",0):拷贝feiy下的文件到 feiy2,不包括子目录

    if(!is_dir($source)){
    echo("Error:the $source is not a direction!");
    return 0;
    }
    if(!is_dir($destination)){
    mkdir($destination,0777);
    }


    $handle=dir($source);
    while($entry=$handle->read()) {
        if(($entry!=".")&&($entry!="..")){
            if(is_dir($source."/".$entry)){
                if($child)    xCopy($source."/".$entry,$destination."/".$entry,$child);
            }else{
                copy($source."/".$entry,$destination."/".$entry);
            }
        }
    }
    return true;
}

function del_file($directory)
{
    $handle = opendir( $directory );
    while ( $file = readdir($handle) )
    {
        $bdir = $directory . '/' .$file;
	
        if ($file <> '.' && $file <> '..' && is_dir($bdir))
        {
            del_file( $directory .'/'. $file);
        }
        else if( $file <> '.' && $file <> '..')
        {
            unlink($directory .'/'. $file );
        }
	
    }
    closedir( $handle );
}

function delete_directory($dirname) {
    if (is_dir($dirname))
        $dir_handle = opendir($dirname);
    if (!$dir_handle)
        return false;
    while($file = readdir($dir_handle)) {
        if ($file != "." && $file != "..") {
            if (!is_dir($dirname."/".$file))
                unlink($dirname."/".$file);
            else
                delete_directory($dirname.'/'.$file);           
        }
    }
    closedir($dir_handle);
    rmdir($dirname);
    return true;
}
$temp=randname();
if(!is_dir("temp/".$temp))mkdir("temp/".$temp);
if(!is_dir("shuqian"))mkdir("shuqian");
xCopy("template/","temp/$temp/",1);
$mf="Manifest-Version: 1.0\n";
$mf.="MicroEdition-Configuration: CLDC-1.0\n";
$mf.="MIDlet-Name: $name\n";
$mf.="MIDlet-Vendor: qt3g.com\n";
$mf.="MIDlet-1: $name,/ico.png,Wapday\n";
$mf.="url: $url\n";
$mf.="MIDlet-Version: 1.0.0\n";
$mf.="MicroEdition-Profile: MIDP-2.0\n";

$f=fopen("temp/$temp/META-INF/MANIFEST.MF","w");
fwrite($f,$mf);
fclose($f);
include_once "pclzip.php";
$archive = new PclZip("shuqian/$temp.jar");			
$archive->create("temp/$temp",PCLZIP_OPT_REMOVE_PATH,"temp/$temp");
delete_directory("temp/$temp/");
$boddy="shuqian/".$temp.".jar";
header("Location: index1.asp?body=$boddy&cc=$cc&ve=$ve"); 

?>